# _*_ coding:utf-8 _*_

import pymysql
from utils import readConfig

readConfigObj = readConfig.ReadConfig("\\config\\env.ini")

def getDbData(database,sql):
    dbUrl = readConfigObj.getConfig("DB","url")
    dbUser = readConfigObj.getConfig("DB","usr")
    dbPw = readConfigObj.getConfig("DB","pw")
    dbDataBase = database
    # 链接数据库
    db = pymysql.connect(dbUrl, dbUser, dbPw, dbDataBase)
    # 创建一个游标对象
    cursor = db.cursor()
    data = cursor.execute(sql)
    print(data)
    db.close()
    return data

def executeDb(database,sql):
    dbUrl = readConfigObj.getConfig("DB", "url")
    dbUser = readConfigObj.getConfig("DB", "usr")
    dbPw = readConfigObj.getConfig("DB", "pw")
    dbDataBase = database
    # 链接数据库
    db = pymysql.connect(dbUrl, dbUser, dbPw, dbDataBase)
    # 创建一个游标对象
    cursor = db.cursor()
    data = cursor.execute(sql)
    db.commit()
    db.close()
    return data



